﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VoteServices.VoteModel;

namespace VoteServices
{
    public class UserService
    {
        VoteData data = new VoteData();
        public User Login()
        {
            Boolean T = true;
            int num = 6;
            User accout = null;
            string id;
            Console.WriteLine("请输入你的账户");
            while (T)
            {
                id = Console.ReadLine();
                accout = data.users.FirstOrDefault(p => p.Account== id);
                if (accout == null)
                {
                    Console.WriteLine("你输入的账户有误，请重新输入！");
                }
                else
                {
                    while (num >= 4)
                    {
                        Console.WriteLine("请输入你的密码！");
                        string password = Console.ReadLine();
                        if (accout .Password.Equals(password))
                        {
                            Console.WriteLine("登入成功,欢迎你,账号为{0}的{1}", accout.Account, accout.Name);
                            T = false;
                            return accout;
                        }
                        else
                        {
                            Console.WriteLine("密码有错误，请重新输入（只有三次机会）！");
                            num--;
                        }
                    }
                    Console.WriteLine("三次机会用完，系统自动退出！");
                    System.Environment.Exit(0);

                }
            }
            return accout;
        }
    }
}